import { apiPatchMindMap, apiNewMindMap, apiDeleteMindMap, apiMapJsonFullUpdate, apiSetMindCoverImage } from '@/apis/mind'

/**
 * 增量更新画布JSON数据
 * @param {*} mindId
 * @param {*} mapId
 * @param {*} delta
 */
export function incrementalUpdateMapJson (mindId, mapId, delta) {
  apiPatchMindMap({
    mindId,
    mapId,
    delta
  })
}

/**
 * 导图内创建新画布
 * @param {*} mindId
 * @param {*} mapJson
 */
export async function newMindMapJson (mindId, mapJson) {
  try {
    await apiNewMindMap({ mindId, mapJson })
  } catch (error) {
    throw new Error(error.message)
  }
}

/**
 * 导图内删除画布
 * @param {*} mindId
 * @param {*} mapId
 */
export async function deleteMindMapJson (mindId, mapId) {
  try {
    await apiDeleteMindMap({ mindId, mapId })
  } catch (error) {
    throw new Error(error.message)
  }
}

/**
 * 画布数据全量更新
 * @param {*} mindId
 * @param {*} mapId
 * @param {*} mapJson
 */
export async function mapJsonFullUpdate (mindId, mapId, mapJson) {
  try {
    await apiMapJsonFullUpdate({ mindId, mapId, mapJson })
  } catch (error) {
    throw new Error(error.message)
  }
}

/**
 * 导图封面图生成
 * @param {*} mindId
 */
export function generateCoverImage (mindId) {
  apiSetMindCoverImage(mindId)
}
